#include "look1_is16lftf_binlcapw.h"
#include "rtwtypes.h"

real32_T look1_is16lftf_binlcapw(int16_T u0, const int16_T bp0[], const real32_T
  table[], uint32_T maxIndex)
{
  real32_T frac;
  real32_T y;
  uint32_T iLeft;
  if (u0 <= bp0[0U]) {
    iLeft = 0U;
    frac = 0.0F;
  } else if (u0 < bp0[maxIndex]) {
    uint32_T bpIdx;
    uint32_T iRght;
    bpIdx = maxIndex >> 1U;
    iLeft = 0U;
    iRght = maxIndex;
    while (iRght - iLeft > 1U) {
      if (u0 < bp0[bpIdx]) {
        iRght = bpIdx;
      } else {
        iLeft = bpIdx;
      }

      bpIdx = (iRght + iLeft) >> 1U;
    }

    int16_T bpLeftVar;
    bpLeftVar = bp0[iLeft];
    frac = (real32_T)(uint16_T)(u0 - bpLeftVar) / (real32_T)(uint16_T)(bp0[iLeft
      + 1U] - bpLeftVar);
  } else {
    iLeft = maxIndex;
    frac = 0.0F;
  }

  if (iLeft == maxIndex) {
    y = table[iLeft];
  } else {
    real32_T yL_0d0;
    yL_0d0 = table[iLeft];
    y = (table[iLeft + 1U] - yL_0d0) * frac + yL_0d0;
  }

  return y;
}
